package gupiao.cn.lhl.dao.impl;

import gupiao.cn.lhl.dao.IStuckDao;
import gupiao.cn.lhl.entity.Stuck;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * Created by Administrator on 2017/4/2/002. */
@Repository
public class StuckDaoImpl implements IStuckDao {
    @Resource
    JdbcTemplate jdbcTemplate;
    public int addStuck(Stuck stuck) {
        String sql="insert into stuck(sname,scount) values(?,?)";
        return jdbcTemplate.update(sql,stuck.getSname(),stuck.getScount());
    }

    public int updateStuck(int count, int sid, boolean is) {
        String sql="";
        if(is){
            sql="update stuck set scount=scount-? where sid=?";
        }else{
            sql="update stuck set scount=scount+? where sid=?";
        }
        return jdbcTemplate.update(sql,count,sid);
    }
}
